﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace com.eforceglobal.crux.configuration.FeatureManager
{
    public class FeatureManager : IFeatureManager
    {

        public bool IsFeatureSupported(string FeatureName)
        {
            XDocument cruxConfigurationDocument = CruxConfigurationManager.LoadConfigFile();
            if (cruxConfigurationDocument != null)
            {
                XElement supportElement =
                    cruxConfigurationDocument.Element("CruxConfigurations")
                        .Element("ApplicationFeatures")
                        .Elements("Feature").FirstOrDefault(p => p.Attribute("Name").Value == FeatureName);

                if (supportElement != null)
                {
                    string supportFeature = supportElement.Attribute("Enabled").Value;
                    return bool.Parse(supportFeature);
                }
            }
            return false;
        }
    }
}
